﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Borders="clr-namespace:ToggleSwitch.Borders" 
                    xmlns:ToggleSwitch="clr-namespace:ToggleSwitch" 
                    xmlns:Utils="clr-namespace:ToggleSwitch.Utils">

    <!--  ClippingBorder style  -->
    <Style TargetType="Borders:ClippingBorder">
        <Setter Property="ClipContent" Value="True" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="TabNavigation" Value="Once" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Borders:ClippingBorder">
                    <Border x:Name="PART_Border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{TemplateBinding CornerRadius}">
                        <Grid>
                            <ContentControl x:Name="PART_TopLeftContentControl"
                                            HorizontalAlignment="Stretch"
                                            VerticalAlignment="Stretch"
                                            HorizontalContentAlignment="Stretch"
                                            VerticalContentAlignment="Stretch" IsTabStop="False">
                                <ContentControl.Clip>
                                    <RectangleGeometry x:Name="PART_TopLeftClip" />
                                </ContentControl.Clip>
                                <ContentControl x:Name="PART_TopRightContentControl"
                                                HorizontalAlignment="Stretch"
                                                VerticalAlignment="Stretch"
                                                HorizontalContentAlignment="Stretch"
                                                VerticalContentAlignment="Stretch" IsTabStop="False">
                                    <ContentControl.Clip>
                                        <RectangleGeometry x:Name="PART_TopRightClip" />
                                    </ContentControl.Clip>
                                    <ContentControl x:Name="PART_BottomRightContentControl"
                                                    HorizontalAlignment="Stretch"
                                                    VerticalAlignment="Stretch"
                                                    HorizontalContentAlignment="Stretch"
                                                    VerticalContentAlignment="Stretch" IsTabStop="False">
                                        <ContentControl.Clip>
                                            <RectangleGeometry x:Name="PART_BottomRightClip" />
                                        </ContentControl.Clip>
                                        <ContentControl x:Name="PART_BottomLeftContentControl"
                                                        HorizontalAlignment="Stretch"
                                                        VerticalAlignment="Stretch"
                                                        HorizontalContentAlignment="Stretch"
                                                        VerticalContentAlignment="Stretch" IsTabStop="False">
                                            <ContentControl.Clip>
                                                <RectangleGeometry x:Name="PART_BottomLeftClip" />
                                            </ContentControl.Clip>
                                            <ContentPresenter Margin="{TemplateBinding Padding}" />
                                        </ContentControl>
                                    </ContentControl>
                                </ContentControl>
                            </ContentControl>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  InnerGlowBorder style  -->
    <Style TargetType="Borders:InnerGlowBorder">
        <Setter Property="InnerGlowSize" Value="10,10,10,10" />
        <Setter Property="InnerGlowOpacity" Value="0.5" />
        <Setter Property="InnerGlowColor" Value="Black" />
        <Setter Property="ClipContent" Value="True" />
        <Setter Property="ContentZIndex" Value="0" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="BorderThickness" Value="1,1,1,1" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="TabNavigation" Value="Once" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Borders:InnerGlowBorder">
                    <Borders:ClippingBorder Background="{TemplateBinding Background}"
                                            BorderBrush="{TemplateBinding BorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            ClipContent="{TemplateBinding ClipContent}"
                                            CornerRadius="{TemplateBinding CornerRadius}">
                        <Grid>
                            <ContentPresenter Margin="{TemplateBinding Padding}" Canvas.ZIndex="{TemplateBinding ContentZIndex}" />
                            <Border x:Name="PART_LeftGlow"
                                    Width="10"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Stretch"
                                    Canvas.ZIndex="0"
                                    IsHitTestVisible="False"
                                    Opacity="{TemplateBinding InnerGlowOpacity}">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0, 0.5" EndPoint="1, 0.5">
                                        <GradientStop x:Name="PART_LeftGlowStop0" Offset="0" Color="Black" />
                                        <GradientStop x:Name="PART_LeftGlowStop1" Offset="1" Color="#00000000" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border x:Name="PART_TopGlow"
                                    Height="10"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Top"
                                    Canvas.ZIndex="0"
                                    IsHitTestVisible="False"
                                    Opacity="{TemplateBinding InnerGlowOpacity}">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1">
                                        <GradientStop x:Name="PART_TopGlowStop0" Offset="0" Color="Black" />
                                        <GradientStop x:Name="PART_TopGlowStop1" Offset="1" Color="#00000000" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border x:Name="PART_RightGlow"
                                    Width="10"
                                    HorizontalAlignment="Right"
                                    VerticalAlignment="Stretch"
                                    Canvas.ZIndex="0"
                                    IsHitTestVisible="False"
                                    Opacity="{TemplateBinding InnerGlowOpacity}">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="1, 0.5" EndPoint="0, 0.5">
                                        <GradientStop x:Name="PART_RightGlowStop0" Offset="0" Color="Black" />
                                        <GradientStop x:Name="PART_RightGlowStop1" Offset="1" Color="#00000000" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Border x:Name="PART_BottomGlow"
                                    Height="10"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Bottom"
                                    Canvas.ZIndex="0"
                                    IsHitTestVisible="False"
                                    Opacity="{TemplateBinding InnerGlowOpacity}">
                                <Border.Background>
                                    <LinearGradientBrush StartPoint="0.5, 1" EndPoint="0.5, 0">
                                        <GradientStop x:Name="PART_BottomGlowStop0" Offset="0" Color="Black" />
                                        <GradientStop x:Name="PART_BottomGlowStop1" Offset="1" Color="#00000000" />
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </Grid>
                    </Borders:ClippingBorder>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--  OuterGlowBorder style  -->
    <Style TargetType="Borders:OuterGlowBorder">
        <Setter Property="OuterGlowSize" Value="10" />
        <Setter Property="OuterGlowOpacity" Value="0.5" />
        <Setter Property="OuterGlowColor" Value="Black" />
        <Setter Property="ClipContent" Value="True" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="Black" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="TabNavigation" Value="Once" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Borders:OuterGlowBorder">
                    <Grid>
                        <Border x:Name="PART_OuterGlowBorder"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                CornerRadius="{TemplateBinding ShadowCornerRadius}"
                                IsHitTestVisible="False"
                                Opacity="{TemplateBinding OuterGlowOpacity}">
                            <Border.Background>
                                <LinearGradientBrush MappingMode="RelativeToBoundingBox" StartPoint="0.5,0" EndPoint="0.5,1">
                                    <GradientStop x:Name="PART_ShadowOuterStop1" Offset="0" Color="#00000000" />
                                    <GradientStop x:Name="PART_ShadowVertical1" Offset="0.1" Color="Black" />
                                    <GradientStop x:Name="PART_ShadowVertical2" Offset="0.9" Color="Black" />
                                    <GradientStop x:Name="PART_ShadowOuterStop2" Offset="1" Color="#00000000" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <Border.OpacityMask>
                                <LinearGradientBrush MappingMode="RelativeToBoundingBox" StartPoint="0.0,0.5" EndPoint="1.0,0.5">
                                    <GradientStop Offset="0" Color="#00000000" />
                                    <GradientStop x:Name="PART_ShadowHorizontal1" Offset="0.1" Color="Black" />
                                    <GradientStop x:Name="PART_ShadowHorizontal2" Offset="0.9" Color="Black" />
                                    <GradientStop Offset="1" Color="#00000000" />
                                </LinearGradientBrush>
                            </Border.OpacityMask>
                        </Border>
                        <Borders:ClippingBorder Background="{TemplateBinding Background}"
                                                BorderBrush="{TemplateBinding BorderBrush}"
                                                BorderThickness="{TemplateBinding BorderThickness}"
                                                ClipContent="{TemplateBinding ClipContent}"
                                                CornerRadius="{TemplateBinding CornerRadius}"
                                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter />
                        </Borders:ClippingBorder>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <ControlTemplate x:Key="PresenterContentTemplate" TargetType="ContentControl">
        <Viewbox StretchDirection="DownOnly" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="{TemplateBinding Padding}">
            <ContentPresenter Content="{TemplateBinding Content}" 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        </Viewbox>
    </ControlTemplate>
    <ControlTemplate x:Key="HorizontalThumbTemplate" TargetType="Thumb">
        <Grid Background="Transparent">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="0.25" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="BackgroundAnimation"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="DisabledVisualElement"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="FocusStates">
                    <VisualState x:Name="Focused">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="0.05" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Unfocused"/>
                </VisualStateGroup>
                <VisualStateGroup x:Name="CheckStates">
                    <VisualState x:Name="Unchecked"/>
                    <VisualState x:Name="Checked">
                        <Storyboard>
                            <DoubleAnimation Duration="0" To="-1" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" Storyboard.TargetName="path"/>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Borders:OuterGlowBorder OuterGlowSize="4" OuterGlowOpacity="0.15" BorderThickness="0" OuterGlowColor="Black" Background="Transparent" CornerRadius="4" ShadowCornerRadius="8" IsTabStop="False" >
                <Grid>
                    <Borders:ClippingBorder x:Name="Background" BorderBrush="#FFA2A2A2" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" IsTabStop="False" Background="White">
                        <Border BorderBrush="#FFEBEBEB" BorderThickness="1" CornerRadius="3" Background="{TemplateBinding Background}">
                            <Path x:Name="path" Data="M3.6,2.6 L10,2.6 L10,6.6 L3.6,6.6 z M10,0 L15.5,4.6 L10,9.4 z" Fill="#AA767676" Stretch="Fill" StrokeThickness="0" RenderTransformOrigin="0.5,0.5" Margin="7,5" >
                                <Path.RenderTransform>
                                    <ScaleTransform/>
                                </Path.RenderTransform>
                            </Path>
                        </Border>
                    </Borders:ClippingBorder>
                    <Borders:ClippingBorder x:Name="BackgroundAnimation" Background="Black" Opacity="0" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="Black" CornerRadius="4" IsTabStop="False"/>
                    <Rectangle x:Name="DisabledVisualElement" Fill="White" IsHitTestVisible="false" Opacity="0" RadiusY="4" RadiusX="4"/>
                    <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="4" RadiusX="4" Stroke="#FF6DBDD1" StrokeThickness="1"/>
                </Grid>
            </Borders:OuterGlowBorder>
        </Grid>
    </ControlTemplate>
    <Style TargetType="ToggleSwitch:HorizontalToggleSwitch">
        <Setter Property="Width" Value="88"/>
        <Setter Property="Height" Value="25"/>
        <Setter Property="BorderBrush" Value="#77979797"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Padding" Value="0,4"/>
        <Setter Property="UncheckedForeground" Value="White"/>
        <Setter Property="CheckedForeground" Value="White" />
        <Setter Property="ThumbSize" Value="40"/>
        <Setter Property="FontWeight" Value="SemiBold"/>
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="ContentTemplate" Value="{StaticResource PresenterContentTemplate}"/>
        <Setter Property="ThumbTemplate" Value="{StaticResource HorizontalThumbTemplate}"/>
        <Setter Property="TabNavigation" Value="Once"/>
        <Setter Property="CheckedBackground">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF5EAD09" Offset="1"/>
                    <GradientStop Color="#FF478108"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="UncheckedBackground">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFC80000" Offset="1"/>
                    <GradientStop Color="#FFB00000"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="ThumbBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFE2E2E2" Offset="1"/>
                    <GradientStop Color="#FFFDFCFD"/>
                    <GradientStop Color="#FFF8F8F8" Offset="0.5"/>
                    <GradientStop Color="#FFE8E8E8" Offset="0.5"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ToggleSwitch:HorizontalToggleSwitch">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="DisabledOverlay">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CheckStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.10" To="Unchecked"/>
                                    <VisualTransition GeneratedDuration="0:0:0.10" To="Checked"/>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Checked"/>
                                <VisualState x:Name="Unchecked"/>
                                <VisualState x:Name="DraggingChecked"/>
                                <VisualState x:Name="DraggingUnchecked"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Unfocused"/>
                                <VisualState x:Name="Focused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Borders:ClippingBorder x:Name="SwitchRoot" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="4" BorderThickness="1" >
                            <Canvas MinWidth="{TemplateBinding ThumbSize}" MinHeight="{TemplateBinding FontSize}">
                                <Utils:ActualSizePropertyProxy x:Name="ActualSizeProxy" Element="{Binding Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" Visibility="Collapsed"/>
                                <Grid x:Name="SwitchTrack" Cursor="Hand" Margin="0,-1,0,0" Height="{Binding ActualHeightValue, ElementName=ActualSizeProxy, Mode=OneWay}" >
                                    <StackPanel Orientation="Horizontal">
                                        <Border Background="{TemplateBinding CheckedBackground}" Margin="-1,0,0,0" Padding="1,0,0,0">
                                            <ContentControl x:Name="SwitchChecked" 
                                                Content="{TemplateBinding CheckedContent}"
                                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
                                                Margin="{TemplateBinding Padding}"
                                                Template="{TemplateBinding ContentTemplate}" 
                                                Foreground="{TemplateBinding CheckedForeground}" IsTabStop="False" Padding="0,0,22,0" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                        </Border>
                                        <Border Background="{TemplateBinding UncheckedBackground}" Margin="-1,0,0,0">
                                            <ContentControl x:Name="SwitchUnchecked" 
                                                Content="{TemplateBinding UncheckedContent}" 
                                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                Margin="{TemplateBinding Padding}"
                                                Template="{TemplateBinding ContentTemplate}"
                                                Foreground="{TemplateBinding UncheckedForeground}" IsTabStop="False" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                        </Border>
                                    </StackPanel>
                                </Grid>
                                <Borders:InnerGlowBorder 
                                    InnerGlowSize="2,4,2,0" 
                                    IsHitTestVisible="False" 
                                    InnerGlowOpacity="0.25" 
                                    BorderThickness="0" 
                                    InnerGlowColor="Black" 
                                    Background="#00000000"
                                    Height="{Binding ActualHeightValue, ElementName=ActualSizeProxy, Mode=OneWay}" 
                                    Width="{Binding ActualWidthValue, ElementName=ActualSizeProxy, Mode=OneWay}" 
                                    Margin="-1,-1,0,0" 
                                    CornerRadius="4" />
                                <Thumb x:Name="SwitchThumb" 
                                    Background="{TemplateBinding ThumbBrush}" 
                                    Template="{TemplateBinding ThumbTemplate}" 
                                    Cursor="Hand" 
                                    Margin="0,-1,0,0" 
                                    Height="{Binding ActualHeightValue, ElementName=ActualSizeProxy, Mode=OneWay}" 
                                    Width="{TemplateBinding ThumbSize}"
                                    HorizontalAlignment="Left" 
                                    BorderBrush="{TemplateBinding BorderBrush}"/>
                            </Canvas>
                        </Borders:ClippingBorder>
                        <Border x:Name="DisabledOverlay" Background="#AAEEEEEE" Visibility="Collapsed" CornerRadius="4"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>